-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to define and update a defaultPath for applications #64498
Allow to define and update a defaultPath for applications #64498
Conversation
Pinging @elastic/kibana-platform (Team:Platform) |
* When defined, this value will be used as a default for the `path` option when calling {@link ApplicationStart.navigateToApp | navigateToApp}`, | ||
* and will also be appended to the {@link ChromeNavLink | application navLink} in the navigation bar. | ||
*/ | ||
defaultPath?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this is on AppBase
because AppUpdatableFields
is a pick from this root class (and I didn't want to overcomplexify the AppUpdatableFields
type with generics). However this property is only used for KP apps. This will be cleaned up 'naturally' once we drop legacy support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we mark it as @deprecated
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not deprecated. It's just that even if on AppBase
, it's effectively only usable by the KP App
subclass, and not the LegacyApp
one.
const getKibanaUrl = (pathname?: string, search?: string) => | ||
url.format({ | ||
protocol: 'http:', | ||
hostname: process.env.TEST_KIBANA_HOST || 'localhost', | ||
port: process.env.TEST_KIBANA_PORT || '5620', | ||
pathname, | ||
search, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this is the third duplication of this helper in test/plugin_functional/test_suites/core_plugins/*
files. I would gladly extract it to an util file, however I'm unsure of the conventions for such files in FTR code. Moving it to a service seems overkill as it's 'stateless'. Any idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR already uses utils decalred in https://github.com/elastic/kibana/blob/8e9a8a84dccfa7965ce8a22362885e6cdef8b51f/src/test_utils/get_url.js
you can extend it
* Utility to remove trailing, leading or duplicate slashes. | ||
* By default will only remove duplicates. | ||
*/ | ||
export const removeSlashes = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I move this to src/core/utils
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider to move it when needed in another place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulled this into my cutover PR, renamed the property and everything continues to work. LGTM, great job! No detailed code review
@pgayvallet I found a minor issue - in |
@flash1293 good catch, thanks. I did not want to introduce a new field, which is why I choose to alter the |
@pgayvallet Noticed another problem - I thought it would be irrelevant first, but it seems like it's breaking the history object in some cases. In https://github.com/elastic/kibana/pull/64498/files#diff-1ab7c26e3c5a0d226f771d13620db1e3L88 it's stripping away trailing slashes. But those are required for these cases: Edit: nvm, seems to be an unrelated problem. |
@flash1293 the recent links issue should be fixed. I also fixed the trailing |
@pgayvallet Tested the fix and everything works fine now, thanks 👍 |
expect(MockHistory.push).toHaveBeenCalledWith('/app/app1', undefined); | ||
MockHistory.push.mockClear(); | ||
|
||
updater.next(app => ({ defaultPath: 'default-path' })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from this example I'd expect it to be called as defaultSubpath
/ internalPath
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the default
part is important as the prop is used as a default in navigateToApp
.
However in navigateToApp
, the app path option is called path
, not subPath
, so I choose defaultPath
.
But I'm fine with defaultSubPath
if we think this is more explicit.
it('preserves trailing slash when path contains a hash', async () => { | ||
const { register } = service.setup(setupDeps); | ||
|
||
register(Symbol(), createApp({ id: 'app2', appRoute: '/custom/path' })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it used in the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adapted this rather quickly. The navigateToApp('myTestApp', { path: '#/' })
below should be using this app2
instead. Will fix.
|
||
const { navigateToApp } = await service.start(startDeps); | ||
await navigateToApp('myTestApp', { path: '#/' }); | ||
expect(MockHistory.push).toHaveBeenCalledWith('/app/myTestApp#/', undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add an assertion when #
not present
* When defined, this value will be used as a default for the `path` option when calling {@link ApplicationStart.navigateToApp | navigateToApp}`, | ||
* and will also be appended to the {@link ChromeNavLink | application navLink} in the navigation bar. | ||
*/ | ||
defaultPath?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we mark it as @deprecated
?
return url; | ||
}; | ||
|
||
export const appendAppPath = (appBasePath: string, path: string = '') => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there any tests for appendAppPath
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, this was introduced in my last commit, and I did not add proper coverage for it. Will add.
* Utility to remove trailing, leading or duplicate slashes. | ||
* By default will only remove duplicates. | ||
*/ | ||
export const removeSlashes = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider to move it when needed in another place
const getKibanaUrl = (pathname?: string, search?: string) => | ||
url.format({ | ||
protocol: 'http:', | ||
hostname: process.env.TEST_KIBANA_HOST || 'localhost', | ||
port: process.env.TEST_KIBANA_PORT || '5620', | ||
pathname, | ||
search, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR already uses utils decalred in https://github.com/elastic/kibana/blob/8e9a8a84dccfa7965ce8a22362885e6cdef8b51f/src/test_utils/get_url.js
you can extend it
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
* master: (42 commits) [Ingest] Allow aggent to send metadata compliant with ECS (elastic#64452) [Endpoint] Remove todos, urls to issues (elastic#64833) [Uptime] Remove hard coded value for monitor states histograms (elastic#64396) Feature/send feedback link (elastic#64845) [ML] Moving get filters capability to admin (elastic#64879) Remove edit alert button from alerts list (elastic#64643) [EPM] Handle constant_keyword type in KB index patterns and ES index templates (elastic#64876) [ML] Disable data frame anaylics clone button based on permission (elastic#64830) Dashboard url generator to preserve saved filters from destination dashboard (elastic#64767) add generic typings for SavedObjectMigrationFn (elastic#63943) Allow to define and update a defaultPath for applications (elastic#64498) [Event Log] add rel=primary to saved objects for query targets (elastic#64615) [Lens] Use a size of 5 for first string field in visualization (elastic#64726) [SIEM][Lists] Removes plugin dependencies, adds more unit tests, fixes more TypeScript types [Ingest] Edit datasource UI (elastic#64727) [Lens] Bind all time fields to the time picker (elastic#63874) [Lens] Use suggestion system in chart switcher for subtypes (elastic#64613) Improve alpha messaging (elastic#64692) [Ingest] Allow to enable monitoring of elastic agent (elastic#63598) [Metrics UI] Fix alerting when a filter query is present (elastic#64575) ...
Summary
Fix #56027
Add a
defaultPath
property to applications and to their updatable fields, and use it inapplication.navigateToApp
and in the UI navlinks urls.Checklist
Dev Docs
KP applications can now define and update the defaultPath that should be used when navigating to them from another application or from the navigation bar.